﻿/*
 Copyright (c) 2011.  Dirk Gordon

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;


namespace File_CRC32_Verifier_WPF
{
    /// <summary>
    /// The FileInformation class stores information about files to be hashed.
    /// </summary>
    public class FileInformation : INotifyPropertyChanged
    {
        private string _fileName;
        private string _expectedCRC;
        private string _actualCRC;
        private int _progress;
        private CRCmatch _crcMatch = CRCmatch.Unknown;

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Create a file information object with just a filename.
        /// </summary>
        /// <param name="fileName">The filename of the file to be hashed.</param>
        public FileInformation(string fileName)
        {
            _fileName = fileName;
            _expectedCRC = "Unknown";
            _actualCRC = "";
            _progress = 0;
        }

        /// <summary>
        /// Create a file information object with all properties.
        /// </summary>
        /// <param name="fileName">The filename of the file to be hashed.</param>
        /// <param name="expectedCRC">The expected file CRC.</param>
        /// <param name="actualCRC">The actual file CRC.</param>
        /// <param name="progress">The progress completed percentage (0-100).</param>
        public FileInformation(string fileName, string expectedCRC, string actualCRC, int progress)
        {
            _fileName = fileName;
            _expectedCRC = expectedCRC;
            _actualCRC = actualCRC;
            _progress = progress;
        }

        /// <summary>
        /// The CRCmatch enumeration stores the state of expected CRC versus actual CRC.
        /// Unknown is when the actual CRC hasn't been calculated or if no expected CRC is found.
        /// True is when expected CRC and actual CRC match.
        /// False is when expected CRC and actual CRC do not match.
        /// </summary>
        public enum CRCmatch
        {
            Unknown, True, False
        }

        /// <summary>
        /// Gets and sets the filename.
        /// </summary>
        public string fileName
        {
            get
            {
                return _fileName;
            }
            set
            {
                _fileName = value;
            }
        }

        /// <summary>
        /// Gets and sets the expected CRC.
        /// </summary>
        public string expectedCRC
        {
            get
            {
                return _expectedCRC;
            }
            set
            {
                _expectedCRC = value;
            }
        }

        /// <summary>
        /// Gets and sets the actual CRC.
        /// </summary>
        public string actualCRC
        {
            get
            {
                return _actualCRC;
            }
            set
            {
                _actualCRC = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("actualCRC"));
                }
            }
        }

        /// <summary>
        /// Gets or sets the progress (0-100).
        /// </summary>
        public int progress
        {
            get
            {
                return _progress;
            }
            set
            {
                _progress = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("progress"));
                }
            }
        }

        /// <summary>
        /// Gets or sets the CRC match status.
        /// </summary>
        public CRCmatch crcMatch
        {
            get
            {
                return _crcMatch;
            }
            set
            {
                _crcMatch = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("crcMatch"));
                }
            }
        }
    }
}
